package com.cskaoyan.controller;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.pojo.MarketAdmin;
import com.cskaoyan.module.pojo.MarketRole;
import com.cskaoyan.module.pojo.MarketStorage;
import com.cskaoyan.module.systemVO.PermissionsBO;
import com.cskaoyan.service.SystemService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/06/20:11
 */
@RestController
@RequestMapping("admin")
public class SystemController {

    @Autowired
    SystemService systemService;

    @Value("${my.path}")
    String path;


    @GetMapping("admin/list")
    @ResponseBody
    public BaseRespVo adminList(Integer page, Integer limit, String username, String sort, String order) {
        BaseRespVo baseRespVo = systemService.listAdmin(page, limit, username, sort, order);
        return baseRespVo;
    }

    @PostMapping("admin/create")
    @ResponseBody
    public BaseRespVo adminCreate(@RequestBody MarketAdmin marketAdmin) {
        BaseRespVo baseRespVo = systemService.createAdmin(marketAdmin);
        return baseRespVo;
    }

    @PostMapping("admin/update")
    @ResponseBody
    public BaseRespVo adminUpdate(@RequestBody MarketAdmin marketAdmin) {
        BaseRespVo baseRespVo = systemService.updateAdmin(marketAdmin);
        return baseRespVo;
    }

    @PostMapping("admin/delete")
    @ResponseBody
    public BaseRespVo adminDelete(@RequestBody MarketAdmin marketAdmin) {
        BaseRespVo baseRespVo = systemService.deleteAdmin(marketAdmin);
        return baseRespVo;
    }

    @GetMapping("log/list")
    @ResponseBody
    public BaseRespVo listLog(Integer page, Integer limit, String name, String sort, String order) {
        BaseRespVo baseRespVo = systemService.listLog(page, limit, name, sort, order);
        return baseRespVo;
    }


    @GetMapping("role/list")
    @ResponseBody
    public BaseRespVo listRole(Integer page, Integer limit, String name, String sort, String order) {
        BaseRespVo baseRespVo = systemService.listRole(page, limit, name, sort, order);
        return baseRespVo;
    }

    @GetMapping("role/options")
    @ResponseBody
    public BaseRespVo optionsRole() {
        BaseRespVo baseRespVo = systemService.roleOptions();
        return baseRespVo;
    }

    @PostMapping("role/create")
    @ResponseBody
    public BaseRespVo createRole(@RequestBody MarketRole marketRole) {
        BaseRespVo baseRespVo = systemService.createRole(marketRole);
        return baseRespVo;
    }

    @PostMapping("role/update")
    @ResponseBody
    public BaseRespVo updateRole(@RequestBody MarketRole marketRole) {
        BaseRespVo baseRespVo = systemService.updateRole(marketRole);
        return baseRespVo;
    }


    @PostMapping("role/delete")
    @ResponseBody
    public BaseRespVo deleteRole(@RequestBody MarketRole marketRole) {
        BaseRespVo baseRespVo = systemService.deleteRole(marketRole);
        return baseRespVo;
    }

    @PostMapping("storage/create")
    @ResponseBody
    public BaseRespVo storageCreate(@RequestParam("file") MultipartFile uploadFile, HttpServletRequest request) {
        BaseRespVo baseRespVo = systemService.createStorage(uploadFile, request);
        return baseRespVo;
    }


    @GetMapping("storage/list")
    @ResponseBody
    public BaseRespVo storageList(Integer page, Integer limit, String key, String name, String sort, String order) {
        BaseRespVo baseRespVo = systemService.listStorage(page, limit, key, name, sort, order);
        return baseRespVo;
    }

    @PostMapping("storage/update")
    @ResponseBody
    public BaseRespVo storageUpdate(@RequestBody MarketStorage marketStorage) {
        BaseRespVo baseRespVo = systemService.updateStorage(marketStorage);
        return baseRespVo;
    }

    @PostMapping("storage/delete")
    @ResponseBody
    public BaseRespVo storageDelete(@RequestBody MarketStorage marketStorage) {
        BaseRespVo baseRespVo = systemService.deleteStorage(marketStorage);
        return baseRespVo;
    }

    @GetMapping("role/permissions")
    @ResponseBody
    public BaseRespVo rolePermissions(Integer roleId) {
        BaseRespVo baseRespVo = systemService.rolePermissions(roleId);
        return baseRespVo;
    }
    @PostMapping("role/permissions")
    @ResponseBody
    public BaseRespVo rolePermissions2(@RequestBody PermissionsBO permissionsBO) {
        BaseRespVo baseRespVo = systemService.updatePermissions(permissionsBO);
        return baseRespVo;
    }

}
